package pl.PawelAndAlicja.badugiproject.main.Ranking;

import pl.PawelAndAlicja.badugiproject.main.Cards.ClientDeck;
import pl.PawelAndAlicja.badugiproject.main.Cards.FlyweightCard;
import pl.PawelAndAlicja.badugiproject.main.Cards.FlyweightFactoryCard;
import pl.PawelAndAlicja.badugiproject.main.Cards.Hand;

/**
 * Created by Pawel on 2014-11-16.
 */
public class RatingCard {

    /*
    *  Sprawdza sile reki.
    *  Im ręka ma mniej punktow tym jest silniejsza
    * */
    public void checkHand(Hand hand) {
        int handPower = 0;

        setSystemCardPower(checkCardColorSystem(hand));
        setAmountCardPower(checkCardAmount(hand));
        System.out.println("Uklad sily kart (1 - Mocny, 4 - Najslabszy): " + getSystemCardPower());
        System.out.println("Uklad ilosciowy kart (1 - Mocny, 13 - Najslabszy): " + getAmountCardPower());
    }


    /*
    *   Metoda sprawdza sile ukladu kart.
    *   1 - Najmocniejszy uklad
    *   4 - Najslabszy uklad
    *
    * */
    private int checkCardColorSystem(Hand hand) {
        int power = 0;
        Hand locHand = hand;

        ClientDeck tmpDeck = hand.getHand();

        // Sprawdzenie duplikatow po kolorach
        for (int i = 0; i < types.length; i++) {
            if (locHand.getHand().getFlyweightFactoryCard().sizeFlyweightCards(types[i]) == 4 ) {
                power = 4;
                break;
            } else if (locHand.getHand().getFlyweightFactoryCard().sizeFlyweightCards(types[i]) == 3 ) {
                power = 3;
                break;
            } else if (locHand.getHand().getFlyweightFactoryCard().sizeFlyweightCards(types[i]) == 2 ) {
                power = 3;
                // sprawdzamy czy nie ma ukladu kart 1 + 1 + 2 + 0, jesli tak mamy uklad 3 kartowy
                for (int j = 0; j < types.length; j++)
                    if (locHand.getHand().getFlyweightFactoryCard().sizeFlyweightCards(types[j]) == 1) {
                        power = 2;
                        break;
                    }
                break;
            } else if (locHand.getHand().getFlyweightFactoryCard().sizeFlyweightCards(types[i]) == 1 ) {
                power = 1;
            }
        }

//        System.out.println("------------ LOCAL HAND");
//        locHand.showHand();
        return power;
    }

    /*
    *   Metoda sprawdza sile rankingu kart w talii
    *   1 - Najmocniejsza
    *   13 - Najslabsza
    * */
    private int checkCardAmount(Hand hand) {
        int power = 0;

        for (int i = 0; i <types.length; i++) {
            if (hand.getHand().getFlyweightFactoryCard().isEmptyCardCollection(types[i])) {
                continue;
            } else {
                power += hand.getHand().getFlyweightFactoryCard().getMinPowerCard(types[i]);
            }
        }

        // Mamy uklad 4-ro kartowy, czyli bardzo mocny uklad
        if (power == 0)
            power = 1;

        return power;
    }

    private void removeDuplicateInColor() {

    }
    public static void main(String[] args) {

    }


    public int getSystemCardPower() {
        return systemCardPower;
    }

    public void setSystemCardPower(int systemCardPower) {
        this.systemCardPower = systemCardPower;
    }

    public int getAmountCardPower() {
        return amountCardPower;
    }

    public void setAmountCardPower(int amountCardPower) {
        this.amountCardPower = amountCardPower;
    }


    private String types[] = {"Spade","Club","Diamond","Heart"};
    private String names []= {"King", "Queen", "Jack", "10", "9", "8", "7", "6", "5", "4", "3", "2", "Ace"};

    private int systemCardPower;
    private int amountCardPower;
}
